const { globalShortcut, screen } = require('electron');
const EnvContext = require('../../common/context/EnvContext');


exports.callMainWin = function () {
    globalShortcut.register('Alt+CommandOrControl+I', () => {
        const theScrean = screen.getDisplayNearestPoint({ x: screen.getCursorScreenPoint().x, y: screen.getCursorScreenPoint().y })
        let mainWindow = EnvContext.getInstance().getMainWin()
        let theScreanId = EnvContext.getInstance().getLastScreanId()

        if (mainWindow == null) {
            createWindow()
        } else if (theScreanId != theScrean.id) {
            mainWindow.setPosition(screen.getCursorScreenPoint().x, screen.getCursorScreenPoint().y, false)
            EnvContext.getInstance().setLastScreanId(theScrean.id)
            if (!mainWindow.isVisible) {
                mainWindow.show()
            }
        } else if (!mainWindow.isVisible()) {
            mainWindow.show()
        } else if (mainWindow.isVisible()) {
            mainWindow.hide()
        }
    })
}
